import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';


class TextFieldWidget extends StatelessWidget {
 
  // 占位符
  final String? hintText;
   // 输入框前置图标
   final IconData? prefixIconData;
   // 输入框后置图标
    final IconData? suffixIconData;
   // 是否隐藏文本
   bool? obscureText;

   // 输入实时回调
   // The argument type 'Function' can't be assigned to the parameter type 'void Function(String)?'
 Function(String value)? onChanged;
  final TextEditingController? controller;
  FocusNode? focusNode;
  Function(String value)? submit;
   final Function()? onTap;


  TextFieldWidget({
     Key? key,
    this.hintText,
    this.submit,
    this.focusNode,
    this.prefixIconData ,
    this.suffixIconData,
    this.obscureText = false,
    this.onChanged,
    this.controller,
    this.onTap
   }):super(key: key);

  @override
  Widget build(BuildContext context) {
    // 构建输入框
    return TextField(
      focusNode: focusNode,
      controller: controller,
      // 实时输入回调
      onChanged:onChanged,
      //内容提交(按回车)的回调
      onSubmitted: submit,
      // 是否隐藏文本
      obscureText: obscureText as bool,
      // 隐藏文本小圆点的颜色
      cursorColor: Colors.blue,
      // 文本样式
      style: TextStyle(
        color: Colors.blue,
        fontSize: 14.0
      ),
      // 输入框的边框
      decoration: InputDecoration(
        // 提示文本
        labelText: hintText,
        // 提示文本的样式
        labelStyle: TextStyle(color: Colors.blue),
        // 可编辑是 无边框样式
        enabledBorder: UnderlineInputBorder(
          borderSide: BorderSide.none
        ),
        // 获取输入焦点时的边框样式
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide:BorderSide(color: Colors.blueAccent),
        ),
        // 文本前置的图标
        prefixIcon: Icon(
          prefixIconData,
          size: 18,
          color: Colors.blue[100],
        ),
        // 后置图标
        suffixIcon: GestureDetector(
          onTap: onTap,
          child: Icon(
            suffixIconData,
            size:18,
            color: Colors.blue[100],
          ),

        )
      ),
    );
    
  }
}